package algotithm.leetcode.string.test179;

import java.util.Arrays;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/1-14:11
 * @Title 179. 最大数
 */
public class Solution {

    public static void main(String[] args) {
        int[] arr = {3,30,34,5,9};
        Solution solution = new Solution();
        String s = solution.largestNumber(arr);
        System.out.println(s);
    }

    public String largestNumber(int[] num) {
        String[] str = new String[num.length];
        for (int i = 0; i < num.length; i++) {
            str[i] = String.valueOf(num[i]);
        }
        Arrays.sort(str,(o1,o2)->(o2+o1).compareTo(o1+o2));
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length; i++) {
            if (sb.toString().equals("0")) {
                sb.delete(0,1);
            }
            sb.append(str[i]);
        }
        return sb.toString();
    }
}
